package com.example.progressbar.slice;

import com.example.progressbar.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ProgressBar;
import ohos.agp.components.Slider;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

public class MainAbilitySlice extends AbilitySlice implements Slider.ValueChangedListener{
    private ProgressBar progressBar,progressBar1;
    private Text currentText;
    private Slider currentSlider;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        progressBar = (ProgressBar)findComponentById(ResourceTable.Id_progressbar);
        progressBar.setDividerLineColor(Color.RED);
        progressBar1 = (ProgressBar)findComponentById(ResourceTable.Id_progressbar1);

        currentText = (Text) findComponentById(ResourceTable.Id_current_value_text);
        currentSlider = (Slider) findComponentById(ResourceTable.Id_current_value_slider);
        currentSlider.setValueChangedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onProgressUpdated(Slider slider, int position, boolean b) {
        switch (slider.getId()) {
            case ResourceTable.Id_current_value_slider: {
                progressBar.setProgressValue(position);
                progressBar1.setProgressHintText(position+"%");
                currentText.setText(String.valueOf(currentSlider.getProgress()));
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void onTouchStart(Slider slider) {

    }

    @Override
    public void onTouchEnd(Slider slider) {

    }
}
